package br.edu.udc.sistemas.ia5.factory;

import java.sql.ResultSet;
import java.util.Collection;
import java.util.Vector;

import br.edu.udc.sistemas.ia5.entity.Entity;

public class Factory {

	public static Entity[] createByResultSet(Entity obj, ResultSet rst) throws Exception {
		Collection result = new Vector();
		String fields[] = obj.getFieldNames();
		while (rst.next()) {
			Entity objAux = obj.getClass().newInstance();
			String values[] = new String[fields.length];
			
			for (int i = 0; i < fields.length; i++) {
				values[i] = rst.getString(fields[i]);
			}
			objAux.setFieldValues(values);
			result.add(objAux);
		}
		
		return (Entity[]) result.toArray(new Entity[result.size()]);
	}
	
}
